<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const obj = {
        a: 1,
        b: {
          c: 2,
          d: 5,
          e: {
            f: 1,
            g: 2,
          },
        },
        c: 3,
      };
      function tree(data) {
        for (let k1 in data) {
          if (typeof data[k1] !== 'object') {
            console.log(k1, data[k1]);
          } else {
            tree(data[k1]);
            // for (let k2 in data[k1]) {
            //   console.log(k2, data[k1][k2]);
            // }
          }
        }
      }

      tree(obj);
    </script>
  </body>
</html>
